package ecom.beans;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "productstore")
@NamedQueries({
    @NamedQuery(name = "ProductstoreBean.findAll", query = "SELECT p FROM ProductstoreBean p"),
    @NamedQuery(name = "ProductstoreBean.findByIdProductStore", query = "SELECT p FROM ProductstoreBean p WHERE p.idProductStore = :idProductStore"),
    @NamedQuery(name = "ProductstoreBean.findByCity", query = "SELECT p FROM ProductstoreBean p WHERE p.city = :city")})
public class ProductstoreBean implements Serializable, ProductstoreRemote {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_product_store", nullable = false)
    private Long idProductStore;
    @Basic(optional = false)
    @Column(name = "name", nullable = false, length = 50)
    private String name;
    @Basic(optional = false)
    @Column(name = "adress", nullable = false, length = 100)
    private String adress;
    @Basic(optional = false)
    @Column(name = "postal_code", nullable = false, length = 10)
    private String postalCode;
    @Basic(optional = false)
    @Column(name = "city", nullable = false, length = 50)
    private String city;
    @Basic(optional = false)
    @Column(name = "tel", nullable = false, length = 20)
    private String tel;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "productstoreBean")
    private Set<StockBean> stockBeanSet;
    @JoinColumn(name = "iban", referencedColumnName = "iban", nullable = false)
    @ManyToOne(optional = false)
    private AccountBean iban;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "productstoreBean")
    private Set<PurchaseBean> purchaseBeanSet;

    public ProductstoreBean() {
    }

    public ProductstoreBean(Long idProductStore) {
        this.idProductStore = idProductStore;
    }

    public ProductstoreBean(Long idProductStore, String name, String adress, String postalCode, String city, String tel) {
        this.idProductStore = idProductStore;
        this.name = name;
        this.adress = adress;
        this.postalCode = postalCode;
        this.city = city;
        this.tel = tel;
    }

    public ProductstoreBean(String name, String adress, String postalCode, String city, String tel, AccountBean iban) {
        this.name = name;
        this.adress = adress;
        this.postalCode = postalCode;
        this.city = city;
        this.tel = tel;
        this.iban = iban;
    }

    @Override
    public Long getIdProductStore() {
        return idProductStore;
    }

    public void setIdProductStore(Long idProductStore) {
        this.idProductStore = idProductStore;
    }

    @Override
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public Set<StockBean> getStockBeanSet() {
        return stockBeanSet;
    }

    public void setStockBeanSet(Set<StockBean> stockBeanSet) {
        this.stockBeanSet = stockBeanSet;
    }

    @Override
    public AccountBean getIban() {
        return iban;
    }

    public void setIban(AccountBean iban) {
        this.iban = iban;
    }

    public Set<PurchaseBean> getPurchaseBeanSet() {
        return purchaseBeanSet;
    }

    public void setPurchaseBeanSet(Set<PurchaseBean> purchaseBeanSet) {
        this.purchaseBeanSet = purchaseBeanSet;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idProductStore != null ? idProductStore.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductstoreBean)) {
            return false;
        }
        ProductstoreBean other = (ProductstoreBean) object;
        if ((this.idProductStore == null && other.idProductStore != null) || (this.idProductStore != null && !this.idProductStore.equals(other.idProductStore))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "[idProductStore=" + idProductStore + ",name=" + name + ",adress="
                + adress + ",postalCode=" + postalCode + ",city=" + city + ",tel=" + tel
                + ",iban=" + iban.getIban() + ",balance=" + iban.getBalance() + "]";
    }

    @Override
    public Set<StockBean> getProducts() {
        return stockBeanSet;
    }
}
